//判断胜利的函数总和
export function isSuccess(boardData, row, col) {
    return horizontalAxis(boardData, row, col) || verticalAxis(boardData, row, col) || rightBevel(boardData, row, col) || leftBevel(boardData, row, col)
}


//判断横轴胜利
function horizontalAxis(boardData, row, col) {
    let count = 1;
    for (let i = 1; col - i >= 0 && boardData[row][col] === boardData[row][col - i]; i++) {
        count++;
    }
    for (let i = 1; col + i < 15 && boardData[row][col] === boardData[row][col + i]; i++) {
        count++;
    }
    return count >= 5;
}

//纵轴胜利
function verticalAxis(boardData, row, col) {
    let count = 1;
    for (let i = 1; row - i >= 0 && boardData[row][col] === boardData[row - i][col]; i++) {
        count++;
    }
    for (let i = 1; row + i < 15 && boardData[row + i][col] === boardData[row][col]; i++) {
        count++;
    }
    return count >= 5;
}

//判断右对角胜利
function rightBevel(boardData, row, col) {
    let count = 1;
    for (let i = 1; row - i >= 0 && col + i < 15 && boardData[row][col] === boardData[row - i][col + i]; i++) {
        count++
    }
    for (let i = 1; col - i >= 0 && row + i < 15 && boardData[row][col] === boardData[row + i][col - i]; i++) {
        count++
    }
    return count >= 5;
}

//判断左对角胜利
function leftBevel(boardData, row, col) {
    let count = 1;
    for (let i = 1; row - i >= 0 && col - i >= 0 && boardData[row][col] === boardData[row - i][col - i]; i++) {
        count++
    }
    for (let i = 1; row + i < 15 && col + i < 15 && boardData[row][col] === boardData[row + i][col + i]; i++) {
        count++
    }
    return count >= 5;
}
